#pragma once

#include "../Locker/Locker.h"
#include "../CGImysql/DBConnectionPool.h"

#include <pthread.h>
#include <list>

template <typename T>
class ThreadPool
{
public:
    ThreadPool(int actorMode, DBConnectionPool* dbConnPool, int threadNums = 8, int maxRequest_ = 10000);
    ~ThreadPool();

    bool append(T *request, int state);
    bool append(T *request);
private:
    static void* worker(void *arg); // thread function
    void run();

    using WorkerQueue = std::list<T*>;

    int threadNums_;        // number of threads in the thread pool
    pthread_t *threads_;    // an array which descibes the thread pool, the size = threadNums_
    
    int maxRequest_;          // the maximum number of requests allowed in the request queue
    WorkerQueue workerQueue_; // requestqueue
    Locker queueLocker_;      // protect the workerQueue_
    Sem queueStat_;           // whether there are tasks to be done
    
    DBConnectionPool *dbConnectionPool_;
    int actorMode_;
};

template <typename T>
ThreadPool<T>::ThreadPool(int actorMode, DBConnectionPool *dbConnPool, int threadNums, int maxRequest_)
{
}

template <typename T>
ThreadPool<T>::~ThreadPool()
{
}

template <typename T>
bool ThreadPool<T>::append(T *request, int state)
{
    return false;
}

template <typename T>
bool ThreadPool<T>::append(T *request)
{
    return false;
}

template <typename T>
void *ThreadPool<T>::worker(void *arg)
{
    return nullptr;
}

template <typename T>
void ThreadPool<T>::run()
{
}
